package com.yc.vcode;

import com.yc.vcode.bean.VcodeProperties;
import com.yc.vcode.web.VcodeInterceptor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@AutoConfiguration
@ComponentScan("com.yc.vcode")
public class VcodeAutoConfiguration implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/vcode/**")
                .addResourceLocations("file:F:\\_文件柜\\133\\组员(李四)\\yc-133" +
                        "\\vcode-starter\\src\\main\\resources\\static\\vcode/");
    }

    @Resource
    VcodeProperties vcodeProperties;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new VcodeInterceptor())
                .addPathPatterns(vcodeProperties.getScope());
    }
}
